package com.xls.dormitoryservice.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xls.dormitoryservice.entity.Room;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author xls
 * @since 2021-03-23
 */
public interface RoomMapper extends BaseMapper<Room> {

    @Select("SELECT\n" +
            "\tid,\n" +
            "\t( SELECT name FROM building WHERE building = id ) AS building,\n" +
            "\t( SELECT name FROM building WHERE floor = id ) AS floor,\n" +
            "\trno,\n" +
            "\tcurrent,\n" +
            "\tcapacity,\n" +
            "\tCOALESCE(url,'') AS url \n" +
            "FROM\n" +
            "\troom r" +
            "\t${ew.customSqlSegment} ORDER BY r.building, r.floor, r.rno")
    Page<Room> getRoomPage(Page<Room> roomPage, @Param(Constants.WRAPPER) QueryWrapper<Room> roomQueryWrapper);

    @Select("SELECT\n" +
            "\tid,\n" +
            "\t( SELECT name FROM building WHERE building = id ) AS building,\n" +
            "\t( SELECT name FROM building WHERE floor = id ) AS floor,\n" +
            "\trno,\n" +
            "\tcurrent,\n" +
            "\tcapacity,\n" +
            "\tCOALESCE(url,'') AS url \n" +
            "FROM\n" +
            "\troom\n" +
            "WHERE\n" +
            "\tid = #{roomId}")
    Room getRoomVo(String roomId);
}
